Attribute VB_Name = "mdlTree"
Option Explicit

Sub EditParent(FindKey As String, NewParent As String)

End Sub

Sub EditCaption(FindKey As String, NewCaption As String)

End Sub

Sub UpdateList()
    Dim i As Integer

    frmMain.tvBuddyList.Nodes.Clear
    If SortByOnline = True Then
        frmMain.tvBuddyList.Nodes.Add , , "tvOnline", "Online", 1
        frmMain.tvBuddyList.Nodes.Add , , "tvOffline", "Offline", 2
        
        For i = 0 To UBound(List.Buddies) - 1
            frmMain.tvBuddyList.Nodes.Add IIf((List.Buddies(i).Status = "FLN"), "tvOffline", "tvOnline"), tvwChild, List.Buddies(i).Email, List.Buddies(i).FriendlyName, GetListImage(List.Buddies(i).Status)
        Next
        
        frmMain.tvBuddyList.Nodes.Item(1).Expanded = True
        frmMain.tvBuddyList.Nodes.Item(2).Expanded = True
    Else
        
        For i = 0 To List.totalGroups - 1
            frmMain.tvBuddyList.Nodes.Add , , "tv" & Urlencode(List.Groups(i)), List.Groups(i), 1
            frmMain.tvBuddyList.Nodes.Item(i + 1).Expanded = True
        Next
        
        frmMain.tvBuddyList.Nodes.Add , , "tvOffline", "Offline", 2
        
        For i = 0 To UBound(List.Buddies) - 1
            frmMain.tvBuddyList.Nodes.Add IIf((List.Buddies(i).Status = "FLN"), IIf((GroupOffline = True), "tvOffline", "tv" & Urlencode(List.Groups(List.Buddies(i).Group))), "tv" & Urlencode(List.Groups(List.Buddies(i).Group))), tvwChild, List.Buddies(i).Email, List.Buddies(i).FriendlyName, GetListImage(List.Buddies(i).Status)
        Next
        
        frmMain.tvBuddyList.Nodes.Item(1).Expanded = True
        frmMain.tvBuddyList.Nodes.Item(2).Expanded = True
    End If
End Sub

Function GetListImage(Status As String)
    Select Case Status
        Case "FLN"
            GetListImage = 2
        Case "NLN"
            GetListImage = 1
        Case "AWY"
            GetListImage = 3
        Case "BRB"
            GetListImage = 3
        Case "IDL"
            GetListImage = 3
        Case "BSY"
            GetListImage = 4
        Case "LUN"
            GetListImage = 5
        Case "PHN"
            GetListImage = 6
    End Select
End Function

Function GetNodeByKey(Key As String)

End Function

Function GetBuddyByEmail(Email As String)
    Dim Buddy
    For Buddy = 0 To UBound(List.Buddies)
        If List.Buddies(Buddy).Email = Email Then
            GetBuddyByEmail = Buddy
        End If
    Next
End Function

Function GetBuddyByName(Name As String)
    Dim Buddy
    For Buddy = 0 To UBound(List.Buddies)
        If List.Buddies(Buddy).FriendlyName = Name Then
            GetBuddyByName = Buddy
        End If
    Next
End Function
